package com.shrct.businessprocess.organization;

import com.shrct.businessprocess.organization.RCEmployee;
import com.shrct.businessprocess.organization.impl.RCEmployeeImpl;
import com.shrct.businessprocess.process_test.MyProcess;
import com.shrct.businessprocess.process_test.impl.MyProcessImpl;
import edu.fudan.langlab.domain.task.Task;
import edu.fudan.langlab.domain.task.TaskService;
import edu.fudan.langlab.domain.workflow.Activity;
import edu.fudan.langlab.domain.workflow.ProcessManager;
import edu.fudan.mylang.pf.IObjectFactory;
import edu.fudan.mylang.pf.test.BaseTest;
import java.util.Collection;
import org.eclipse.xtext.xbase.lib.InputOutput;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;

@ContextConfiguration(locations = "classpath:HibernateApplicationContext-test.xml")
public class OrgTest extends BaseTest {
  public OrgTest() {
    super();
  }
  
  @Autowired
  private ProcessManager processManager;
  
  @Autowired
  private TaskService taskService;
  
  @Test
  public void justTest1() {RCEmployee rCEmployee=RCEmployeeImpl.create(getObjectFactory());
    final Procedure1<RCEmployee> _function = new Procedure1<RCEmployee>() {
        public void apply(final RCEmployee it) {
          it.setName("sale");
        }
      };
    final RCEmployee sale = ObjectExtensions.<RCEmployee>operator_doubleArrow(rCEmployee, _function);RCEmployee rCEmployee_1=RCEmployeeImpl.create(getObjectFactory());
    final Procedure1<RCEmployee> _function_1 = new Procedure1<RCEmployee>() {
        public void apply(final RCEmployee it) {
          it.setName("manager");
        }
      };
    final RCEmployee manager = ObjectExtensions.<RCEmployee>operator_doubleArrow(rCEmployee_1, _function_1);
    IObjectFactory _objectFactory = this.getObjectFactory();
    MyProcess _create = MyProcessImpl.create(_objectFactory);
    final Procedure1<MyProcess> _function_2 = new Procedure1<MyProcess>() {
        public void apply(final MyProcess it) {
          it.start(sale, manager);
          Collection<Task> _findTasks4Owner = OrgTest.this.taskService.findTasks4Owner(sale);
          int _size = _findTasks4Owner.size();
          Assert.assertEquals(1, _size);
          it.apply();
          Collection<Task> _findTasks4Owner_1 = OrgTest.this.taskService.findTasks4Owner(sale);
          int _size_1 = _findTasks4Owner_1.size();
          Assert.assertEquals(0, _size_1);
          Collection<Task> _findTasks4Owner_2 = OrgTest.this.taskService.findTasks4Owner(manager);
          int _size_2 = _findTasks4Owner_2.size();
          Assert.assertEquals(1, _size_2);
          it.evaluate_reject();
          Collection<Task> _findTasks4Owner_3 = OrgTest.this.taskService.findTasks4Owner(sale);
          int _size_3 = _findTasks4Owner_3.size();
          Assert.assertEquals(1, _size_3);
          it.apply();
          Collection<Task> _findTasks4Owner_4 = OrgTest.this.taskService.findTasks4Owner(manager);
          int _size_4 = _findTasks4Owner_4.size();
          Assert.assertEquals(1, _size_4);
          it.evaluate_confirm();
          Collection<Task> _findTasks4Owner_5 = OrgTest.this.taskService.findTasks4Owner(sale);
          int _size_5 = _findTasks4Owner_5.size();
          Assert.assertEquals(1, _size_5);
          Collection<Task> _findTasks4Owner_6 = OrgTest.this.taskService.findTasks4Owner(manager);
          int _size_6 = _findTasks4Owner_6.size();
          Assert.assertEquals(1, _size_6);
          it.wireMoney("", Double.valueOf(10.0));
          Collection<Task> _findTasks4Owner_7 = OrgTest.this.taskService.findTasks4Owner(manager);
          int _size_7 = _findTasks4Owner_7.size();
          Assert.assertEquals(1, _size_7);
          it.achieve();
          Collection<Task> _findTasks4Owner_8 = OrgTest.this.taskService.findTasks4Owner(sale);
          int _size_8 = _findTasks4Owner_8.size();
          Assert.assertEquals(0, _size_8);
          Collection<Task> _findTasks4Owner_9 = OrgTest.this.taskService.findTasks4Owner(manager);
          int _size_9 = _findTasks4Owner_9.size();
          Assert.assertEquals(0, _size_9);
          it.commit();
          Boolean _isFinished = it.getIsFinished();
          Assert.assertTrue((_isFinished).booleanValue());
          Collection<Activity> _activities = it.getActivities();
          final Procedure1<Activity> _function = new Procedure1<Activity>() {
              public void apply(final Activity it) {
                InputOutput.<Activity>println(it);
              }
            };
          IterableExtensions.<Activity>forEach(_activities, _function);
        }
      };
    ObjectExtensions.<MyProcess>operator_doubleArrow(_create, _function_2);
    IObjectFactory _objectFactory_1 = this.getObjectFactory();
    MyProcess _create_1 = MyProcessImpl.create(_objectFactory_1);
    final Procedure1<MyProcess> _function_3 = new Procedure1<MyProcess>() {
        public void apply(final MyProcess it) {
          it.start(sale, manager);
          it.apply();
          it.evaluate_confirm();
          it.wireMoney("", Double.valueOf(10.0));
          it.achieve();
          it.commit();
          Boolean _isFinished = it.getIsFinished();
          Assert.assertTrue((_isFinished).booleanValue());
          Collection<Activity> _activities = it.getActivities();
          final Procedure1<Activity> _function = new Procedure1<Activity>() {
              public void apply(final Activity it) {
                InputOutput.<Activity>println(it);
              }
            };
          IterableExtensions.<Activity>forEach(_activities, _function);
          Collection<Activity> _activities_1 = it.getActivities();
          int _size = _activities_1.size();
          Assert.assertEquals(7, _size);
        }
      };
    ObjectExtensions.<MyProcess>operator_doubleArrow(_create_1, _function_3);
  }
}
